//
//  WBNavViewController.swift
//  weibo
//
//  Created by 李海超 on 2017/5/21.
//  Copyright © 2017年 lihaichao. All rights reserved.
//

import UIKit

class WBNavViewController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //隐藏自带的navigationBar
        
        navigationBar.isHidden = true
    
    }

  
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count>0 {
            
            viewController.hidesBottomBarWhenPushed = true
            
            if let vc = viewController as? WBBaseViewController {
                
                var title = "返回"
                
                if childViewControllers.count == 1{
                
                    title = childViewControllers.first?.title ?? "返回"
                }
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(backClick), isBack:true)
            }
        }
        
        //调用父类方法之前，栈中不添加元素
        super.pushViewController(viewController, animated: animated)
        
        //调用父类方法之后，才会压站，childViewController元素加一
        
        
    }
    
    @objc private func backClick(){
    
        popViewController(animated: true)
    }
    

}
